const App = getApp()
Page({
  data: {
    check: false,
    oil: '',
    pageShow:false
  },
  onLoad: function (options) {
    let that = this
    that.oil()
  },
  onReady: function () {

  },
  inputtext(e) {
    let that = this
    var money;
    if (/^[0-9]+$/.test(e.detail.value)) { 
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    var price = (money * that.data.setting.day_oil.price).toFixed(2)
    this.setData({
      oil: money,
      price: price
    })
  },
  oil() {
    let that = this
    let address=wx.getStorageSync('address')
    App.api.$http({
      url: 'points.log/detail',
      method: 'Post',
      data: {
        longitude: address.longitude,
        latitude: address.latitude,
      }
    }, {}).then(res => {
      that.setData({
        pageShow:true,
        ...res.data
      })
    })

  },

  // 提交锁价申请
  sure() {
    let that = this
    if (!that.data.oil) {
      App.api.$showSuccess('请输入油品量')
      return
    }
    if (!that.data.check) {
      App.api.$showSuccess('请阅读并勾选协议')
      return
    }
    App.api.$http({
      url: 'points.log/submit',
      method: 'Post',
      data: {
        oil_num:Number(that.data.oil)
      }
    }, {}).then(res => {
      if(res){
        App.api.$showSuccess(res.msg)
        setTimeout(function(){
          wx.navigateBack()
        },2000)
      }
    })
  },
  onShow: function () {

  },
  checkcon() {
    let that = this
    that.setData({
      check: !that.data.check
    })
  },
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})